package offer.easy;

public class ReverseString {

    public static String reSentence(String str) {
        if (str.equals("") || str == null) {
            return str;
        } else {
            String res = "";
            String[] array = str.split(" ");
            if (array.length == 0) {
                return str;
            }
            for (int i = array.length-1; i > 0; i--) {
                res = res + array[i] + " ";
            }
            res = res + array[0];

            return res;
        }
    }

    public static void main(String[] args) {
        String str = "nowcoder. a am I";
        str = reSentence(str);
        System.out.println(str);
    }
}
